home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 3: The Continuation / 17-Bit_The_Continuation_Disc.iso / amigan / amigan 14 / sclock / sclock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-27  |  7.3 KB  |  156 lines

  1. /****************************************************************************
  2.  *                                                                          *
  3.  * Program   : Sclock.c                                                     *
  4.  * Programmer: David C. Lauri Jr.   [DLAURI  PeopleLink, Genie, BIX]        *
  5.  *                                                                          *
  6.  * This is a digital titlebar clock with seconds and AM/PM indicator.       *
  7.  * Its special feature is that it always stays on the active screen, even   *
  8.  * if the active screen is a custom one belonging to another program.       *
  9.  * (Finally, a clock for AMIC PD term!)                                     *
  10.  *                                                                          *
  11.  * User beware:                                                             *
  12.  * Because this clock sometimes "trespasses" on custom screens, special     *
  13.  * care must be taken in its use.  If a custom screen on which it resides   *
  14.  * closes, you will be visited by the GURU.  Therefore, before closing a    *
  15.  * custom screen, close the clock first.  For example, if you want to exit  *
  16.  * AMIC PD term, first close Sclock and then close AMIC PD term.  Then, you *
  17.  * can run Sclock again.                                                    *
  18.  *                                                                          *
  19.  * Having said that, I hereby disclaim any responsibility for damages       *
  20.  * caused by use of this program.  Anyone who feels he can't follow the     *
  21.  * above guideline should not use this program!                             *
  22.  *                                                                          *
  23.  * This program is released into the public domain.  Anyone may do whatever *
  24.  * he wants with it.                                                        *
  25.  *                                                                          *
  26.  ****************************************************************************/
  27.  
  28. #include <libraries/dos.h>
  29. #include <intuition/intuitionbase.h>
  30. #include <lattice/stdio.h>
  31.  
  32. #define    WIN_WIDTH   131                  /* width of the clock's window */
  33. #define    WAIT_TIME   250000               /* how long to wait between
  34.                                                updates in micro-seconds */
  35.  
  36. struct NewWindow newwindow =
  37. { 459, 0,                                   /* Upper left corner
  38.                                                (puts clock just to left
  39.                                                 of the Back/Front gadgets */
  40.   131, 10,                                  /* Width, Height */
  41.   1, 1,                                     /* Foreground, background */
  42.   CLOSEWINDOW,                              /* IDCMP flags */
  43.   WINDOWCLOSE                               /* flags */
  44.     | WINDOWDRAG | SMART_REFRESH | NOCAREREFRESH,
  45.   NULL,                                     /* First gadget */
  46.   NULL,                                     /* Check mark */
  47.   "",                                       /* Title */
  48.   NULL,                                     /* Screen */
  49.   NULL,                                     /* Bit map */
  50.   0, 0, 0, 0,                               /* minimum/maximum sizes */
  51.   WBENCHSCREEN                              /* Workbench type */
  52. };
  53. struct Window *window, *OpenWindow();
  54. struct timerequest timer;
  55. struct MsgPort *timerport, *CreatePort();
  56. struct Screen *workbenchscreen, *currentscreen;
  57.  
  58. char datestring[20];                         /* Place to keep the date */
  59. struct IntuiText datetext =
  60. { 2, 1,                                     /* Foreground, background */
  61.   JAM2,                                     /* Use both pens */
  62.   0, 0,                                     /* Upper left corner */
  63.   NULL,                                     /* Text attributes */
  64.   datestring,                               /* Buffer */
  65.   NULL                                      /* Next IntuiText */
  66. };
  67.  
  68. struct IntuitionBase *IntuitionBase;
  69.  
  70. void
  71. main()
  72. {  int                 notclosed = TRUE;
  73.    register short      hours, minutes;
  74.    char                *time, *am="AM", *pm="PM";
  75.    struct DateStamp    now;
  76.    struct IntuiMessage *message, *GetMsg();
  77.    struct Task         *FindTask();
  78.    
  79.    if((IntuitionBase = (struct IntuitionBase *)
  80.            OpenLibrary("intuition.library", 0)) != NULL)
  81.    { if((timerport = CreatePort("Timer Port", 0)) != NULL)
  82.      { if(OpenDevice(TIMERNAME, UNIT_VBLANK, (char *)&timer, 0) == NULL)
  83.        { timer.tr_node.io_Message.mn_ReplyPort = timerport;
  84.          timer.tr_node.io_Command = TR_ADDREQUEST;
  85.          timer.tr_node.io_Flags = 0;
  86.          timer.tr_node.io_Error = 0;
  87.          
  88.          if((window = OpenWindow(&newwindow)) != NULL)
  89.          { workbenchscreen = window->WScreen;
  90.            currentscreen = window->WScreen;
  91.            
  92.            (void)SetTaskPri(FindTask((char *) 0), 20);
  93.            
  94.            while(notclosed)
  95.            { DateStamp(&now);
  96.              hours = now.ds_Minute / 60;
  97.              if(hours >= 12)
  98.                time = pm;
  99.              else
  100.                time = am;
  101.              if(hours > 12)
  102.                hours = hours - 12;
  103.              if(hours == 0)
  104.                hours = 12;
  105.              minutes = now.ds_Minute % 60;
  106.              
  107.              sprintf(datestring, " %02d:%02d:%02d %2s ",
  108.                         hours, minutes, now.ds_Tick / TICKS_PER_SECOND, time);
  109.              
  110.              PrintIText(window->RPort, &datetext, 28, 1);
  111.              
  112.              timer.tr_time.tv_secs = 0;
  113.              timer.tr_time.tv_micro = WAIT_TIME;
  114.              SendIO((char *) &timer.tr_node);
  115.              Wait(1 << window->UserPort->mp_SigBit
  116.                     | 1 << timerport->mp_SigBit);
  117.              
  118.              while(message = GetMsg(window->UserPort))
  119.              { if(message->Class == CLOSEWINDOW)
  120.                  notclosed = FALSE;
  121.                ReplyMsg(message);
  122.              } /* end while */
  123.              
  124.              (void)GetMsg(timerport);
  125.              if(currentscreen != IntuitionBase->ActiveScreen)
  126.              { newwindow.LeftEdge = window->LeftEdge;
  127.                newwindow.TopEdge = window->TopEdge;
  128.                if(newwindow.TopEdge >= IntuitionBase->ActiveScreen->Height)
  129.                  newwindow.TopEdge = IntuitionBase->ActiveScreen->Height - 1;
  130.                if(window)
  131.                  CloseWindow(window);
  132.                if(IntuitionBase->ActiveScreen == workbenchscreen)
  133.                { newwindow.Screen = NULL;
  134.                  newwindow.Type = WBENCHSCREEN;
  135.                } /* end if(IntuitionBase->ActiveScreen...) */
  136.                else
  137.                { newwindow.Screen = IntuitionBase->ActiveScreen;
  138.                  newwindow.Type = CUSTOMSCREEN;
  139.                } /* end else */
  140.                if((window = (struct Window *)OpenWindow(&newwindow)) != NULL)
  141.                  currentscreen = window->WScreen;
  142.                else
  143.                  notclosed = FALSE;
  144.              } /* end if(currentscreen...) */
  145.            } /* end while(notclosed) */
  146.            if(window)
  147.              CloseWindow(window);
  148.          } /* end if((window = ...) */
  149.          CloseDevice(&timer);
  150.        } /* end if(OpenDevice(TIMERNAME...) */
  151.        DeletePort(timerport);
  152.      } /* end if((timerport = CreatePort("Timer Port", 0)) != NULL) */
  153.      CloseLibrary(IntuitionBase);
  154.    } /* end if((IntuitionBase = (struct IntuitionBase *)...) */
  155. } /* end main () */
  156.